import { reactive } from 'vue';

const store = {
    debug: true,
    state: reactive({
        products: []
    }),


    // 向购物车中添加数据的方法
    addActions(newValue) {
        let flag = true;
        if(this.state.products.length === 0) {
            this.state.products.push(newValue)
        } else {
            this.state.products.forEach(item => {
                if(item.upId == newValue.upId && item.btmId == newValue.btmId) {
                    flag = false;
                    item.num += newValue.num;
                }
                if(flag) {
                    this.state.products.push(newValue)
                }
            })
        }
    },


    // 删除购物车单个数据的逻辑
    delActions(i) {
        this.state.products.splice(i, 1)
    }
}

export default store